package test;
import java.math.BigInteger;

public class Factorial {
	static long[] table = new long[21];
	static {
		table[0] = 1;
	}
	static int last = 0;

	public static long factorial(int x) throws IllegalArgumentException {
		if (x >= table.length) {
			throw new IllegalArgumentException("Overflow; x is too large.");
		}
		if (x <= 0) {
			throw new IllegalArgumentException("x must be non-negative.");
		}
		while (last < x) {
			table[last + 1] = table[last] * (last + 1);
			last++;
		}
		return table[x];
	}

	public static long f(int x) {
		if (x == 1)
			return 1;
		else {
			return x * f(x - 1);
		}
	}

	public static String ff(int x) {
		BigInteger b = BigInteger.valueOf(1);
		for (int i = 1; i <= x; i++) {
			b = b.multiply(BigInteger.valueOf(i));
		}
		return b.toString();
	}

	public static void main(String[] args) {
		System.out.println(Long.MAX_VALUE);
		System.out.println(factorial(20));
		System.out.println(f(20));

		System.out.println();
		System.out.println(ff(2));

		System.out.println();
		int a = 0;
		System.out.println(999*99);

	}
}
